#ifndef _MSSQL_DRIVER_H_
#define _MSSQL_DRIVER_H_
#include <buildspec.h>
#include <Client/ClientUtils/Network/RDBDriverInterface.h>
#include <Client/ClientUtils/Network/AbstractDataTable.h>


namespace GST {
namespace ClientUtils {


class GST_API_EXPORT MSSQLDriver :
	public RDBDriverInterface
{
public:
	/**
	 * @note
	 * If odbcclientversion is empty we try to get it from the registry
	 *
	 * @throw GST::exceptions::GSTNotFound if odbcclientversion is empty and no entry found in registry
	 */
	MSSQLDriver(HostPtr host, const std::string& dbname, const std::string& odbcclientversion = std::string());
	virtual void connect();
	virtual void disconnect();
	virtual ~MSSQLDriver(void);
	virtual bool isConnected();
	virtual int getPID();
	virtual void exec(const std::string & sqlStatement);
	virtual AbstractDataTablePtr exec_returning(const std::string & sqlStatement);
	virtual TableAttributeDescListPtr ListTableAttributeDescs(const std::string & tableName);
	virtual std::string ConcatenateStatements( const StatementBuilder & statements ) const;
	virtual std::string sqlesc(const std::string&) const;
	virtual std::string asUnquotedIdentifier(const std::string& identifier) const;
	bool AllocateStmtHandle(void*& sqlstatementhandle);
	void* execute(void*& sqlstatementhandle, const std::string & sqlStatement, short& returnres);
	AbstractDataTablePtr resultToTable(void*& sqlstatementhandle);
	void FreeStmtHandle(void*& sqlstatementhandle);
	std::string getODBCClientVersion() const;
	std::string GetErrorMessage(unsigned int handletype, void* handle) const;
	//void SetAutocommitOFF();
	//void SetAutocommitON();
	//void SQLCommit();
	//void SQLRollback();
private:
	void* sqlenvhandle;
	void* sqlconnectionhandle;
	std::string odbcclientversion;
	std::string getODBCClientVersionFromRegistryOrThrow() const;
	void createEnvironment();
};

} //of ns ClientUtils
} //of ns GST

#endif //_POSTGRES_DRIVER_H_